﻿using UnityEngine;
using System.Collections;

public abstract class Upgrade : MonoBehaviour {
    //Point the player needs to use before he can buy this upgrade
    [SerializeField]
    protected float modifier;
    public float Modifier
    {
        get { return modifier; }
        set { modifier = value; }
    }

    [SerializeField]
    protected int requiredPointInTree;
    public int RequiredPointInTree
    {
        get { return requiredPointInTree; }
        set { requiredPointInTree = value; }
    }

    //Name to be printed
    [SerializeField]
    protected string printName;
    public string PrintName
    {
        get { return printName; }
        set { printName = value; }
    }

    //The target of the upgrade
    protected TargetofUpgrade upgradeType;
    public TargetofUpgrade UpgradeType
    {
        get { return upgradeType; }
        set { upgradeType = value; }
    }

    //Description to be printed in game on hover
    [SerializeField]
    protected string description;
    public string Description
    {
        get { return printName + "\n" + description; }
        set { description = value; }
    }

    //Effect depends on the level of the upgrade
    [SerializeField]
    protected int maxLevel;
    public int MaxLevel
    {
        get { return maxLevel; }
        set { maxLevel = value; }
    }

    //Current level
    protected int currentLevel;
    public int CurrentLevel
    {
        get { return currentLevel; }
        set { currentLevel = value; }
    }

    //Position in the tree
    [SerializeField]
    protected int treeLevel;
    public int TreeLevel
    {
        get { return treeLevel; }
        set { treeLevel = value; }
    }

    //Rect set up by the GUI at start
    protected Rect guiRect;
    public Rect GUIRect
    {
        get { return guiRect; }
        set { guiRect = value; }
    }

	// Use this for initialization
	void Start () {
        currentLevel = 0;
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    public void buy(GameObject target)
    {
        CurrentLevel++;
        applyEffect(target);
    }

    //Effect of the upgrade
    protected abstract void applyEffect(GameObject target);

    //Check if the buy conditions are verified
    public bool canBuy(int pointInTree)
    {
        return (requiredPointInTree <= pointInTree);
    }

    public bool isLevelMax()
    {
        return (CurrentLevel >= MaxLevel);
    }
}